package com.ruoyi.hospital.controller.statistics;

import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.hospital.dto.HotDoctor;
import com.ruoyi.hospital.dto.HotDrug;
import com.ruoyi.hospital.dto.Nums;
import com.ruoyi.hospital.dto.Piedate;
import com.ruoyi.hospital.service.consultationInfo.IConsultationInfoService;
import com.ruoyi.hospital.service.doctor.IDocInfoService;
import com.ruoyi.hospital.service.member.IMemberInfoService;
import com.ruoyi.hospital.service.order.IShopOrdersService;
import com.ruoyi.system.service.ISysAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 定时任务调度测试
 * 
 * @author ruoyi
 */
@Component("managerTask")
public class ManagerTask
{

    @Autowired
    private RedisCache redisCache;
    @Autowired
    private IDocInfoService iDocInfoService;
    @Autowired
    private IMemberInfoService iMemberInfoService;
    @Autowired
    private IConsultationInfoService iConsultationInfoService;
    @Autowired
    private IShopOrdersService iShopOrdersService;

    /**
     *
     * 使用map 保存首页：医生统计、患者统计、收入统计、药品统计
     * */
    public void nums()
    {
        Nums nums = new Nums();
        //医生数量
        nums.setDocNum(iDocInfoService.getNum());
        //患者数量
        nums.setMemberNum(iMemberInfoService.getNum());
        //收入统计：问诊+商品订单
        //问诊
        nums.setWenzhenf(String.valueOf(iConsultationInfoService.getNum()));
        //商品订单
        nums.setDingdanf(String.valueOf(iShopOrdersService.getNum(null)));
        //商品费用统计：药品，非药品，中草药
        nums.setDrugf(String.valueOf(iShopOrdersService.getNum(0)));
        nums.setDrugnof(String.valueOf(iShopOrdersService.getNum(1)));
        nums.setHerbf(String.valueOf(iShopOrdersService.getNum(2)));
        redisCache.setCacheObject("nums",nums);



    }


    /**
     *
     * 使用map 保存首页：咨询统计  + 热门药店 + 热门医生+ 热销药品
     * */
    public void piedate()
    {
        if(redisCache.hasKey("conDate")){
            redisCache.deleteObject("conDate");
        }
        List<Piedate> piedate = iConsultationInfoService.getPiedate();
        if(piedate.size()>0){
            redisCache.setCacheList("conDate",piedate);

        }


        //药店销量统计
        if(redisCache.hasKey("storeData")){
            redisCache.deleteObject("storeData");
        }
        List<Piedate> storeData = iShopOrdersService.getStoreData();
        if(storeData.size()>0){
            redisCache.setCacheList("storeData",storeData);

        }

        //热门医生
        if(redisCache.hasKey("hotDoctor")){
            redisCache.deleteObject("hotDoctor");
        }
        List<HotDoctor> hotDoctor = iConsultationInfoService.getHotdoctor();
        if(hotDoctor.size()>0){
            redisCache.setCacheList("hotDoctor",hotDoctor);

        }

        //热销药品
        if(redisCache.hasKey("hotDrug")){
            redisCache.deleteObject("hotDrug");
        }
        List<HotDrug> hotDrug = iShopOrdersService.getHotDrug();
        if(hotDrug.size()>0){
            redisCache.setCacheList("hotDrug",hotDrug);

        }
    }



    /**
     *
     * 使用list 保存首页：热门科室、热门医生、热销药品
     * */
    public void hot()
    {
        System.out.println("执行无参方法123");
    }


    @Autowired
    private ISysAddressService iSysAddressService;
    /*
    * 初始化城市
    * */
    public void memberAddress(){
        iSysAddressService.initAddressCache();
    }

}
